1  本周内容
1.1  1.字典的实践（一）
课本P112-113
知识点：
利用字典计算词频
字典的初始化
vowels = ["a","e","i","o","u"]
word = input("请输入")
found = {}
# 方法一循环 vowels
# for i in vowels:  # 可优化 fromkeys()
#    found[i] = 0
# 方法二：利用formkeys 实现初始化值
found = found.fromkeys(vowels.0)
for i in word:
    if i in vowels:
       found[i] +=1
print(found)
vowels = ["a","e","i","o","u"]
word = input("请输入")
found = {}
# 方法一循环 vowels
# for i in vowels:  # 可优化 fromkeys()
#    found[i] = 0
# 方法二：利用formkeys 实现初始化值
found = found.fromkeys(vowels.0)
for i in word:
    if i in vowels:
       found[i] +=1
print(found)
  File "<ipython-input-9-1ef0de3a7338>", line 8
    found = found.fromkeys(vowels.0)
                                  ^
SyntaxError: invalid syntax


2  > 1.字典的高级用法：fromkeys()
给定一个序列数据作为KEY 把序列所有内容进行初始化，作为新的字典内容

names_list = ['Alex','Marry','jack','jan'] # iterable
names_age_dict = {}
names_age_dict = names_age_dict.fromkeys(names_list,123456) # 把一个序列作为一个字典的keys，然后初始化其值(默认值为：NONE)，可以给定一个值
3  > 2. 字典的高级用法setdefault()
1.如果字典中还没有该内容(item),新增该item作为字典的key，默认值

## 2.字典的实践(二)
vowels = ["a","e","i","o","u"]
word = input("请输入")
found = {}
for letter in word:
  if letter in vowels:
   found.setdefault(letter,0)
   found[letter] +=1
found
​
​
​
请输入1
{}
found = {'a':2}
found.setdefault('e',0)
found
{'a': 2, 'e': 0}
# 取值
## people['']['']
​
#Zhichao
​
import pprint
people = {}
people['Ford'] = {"Name":'Ford Prefect',
                  "Gender":'Male',
                  "Occupation":'Researcher',
                  "Home Planet":'Betelgeuse Seven'}
people['Arthur'] = {"Name":'Arthur Dent',
                  "Gender":'Male',
                  "Occupation":'Sandwich-Maker',
                  "Home Planet":'Earth'}
people['Tricia'] = {"Name":'Tricia McMillan',
                    "Gender":'Female',
                    "Occupation":'Mathematician',
                    "Home Planet":'Earth'}
people['Marvin'] = {"Name":'Marvin',
                    "Gender":'Unknown',
                    "Occupation":'Paranoid Android',
                    "Home Planet":'Unknown'}
pprint.pprint(people)
{'Arthur': {'Gender': 'Male',
            'Home Planet': 'Earth',
            'Name': 'Arthur Dent',
            'Occupation': 'Sandwich-Maker'},
 'Ford': {'Gender': 'Male',
          'Home Planet': 'Betelgeuse Seven',
          'Name': 'Ford Prefect',
          'Occupation': 'Researcher'},
 'Marvin': {'Gender': 'Unknown',
            'Home Planet': 'Unknown',
            'Name': 'Marvin',
            'Occupation': 'Paranoid Android'},
 'Tricia': {'Gender': 'Female',
            'Home Planet': 'Earth',
            'Name': 'Tricia McMillan',
            'Occupation': 'Mathematician'}}